/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ufps.cuatro.util.generadores.codeobject;

import com.ufps.cuatro.modelo.representacion.componente.Componente;
import com.ufps.cuatro.modelo.representacion.componente.ComponenteDistribuidorGeneradorUnitario;
import com.ufps.cuatro.modelo.representacion.componente.ComponenteGenerado;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author CATC
 */
public class CodeContextField extends CodeContextType{
    
    private boolean definicionCanonica = true;

    public CodeContextField(Componente objComponente) {
        super(EnumModificador.ePublic, objComponente);
    }    

    @Override
    public ArrayList<CodeContextLine> generateSourceCodeSyntax(EnumTypeCodeSyntax eTypeCodeSintax) {
     try{
        ArrayList<CodeContextLine> objSourceLinesCode = new ArrayList<CodeContextLine>();        
        if(eTypeCodeSintax == EnumTypeCodeSyntax.eImport){
            generateSourceCodeSintaxImport(objSourceLinesCode);
        }
        else if(eTypeCodeSintax == EnumTypeCodeSyntax.eFieldsDefinitionSimple){
            generateSourceCodeSintaxDefinition(objSourceLinesCode);
        }        
        return objSourceLinesCode;
    }catch(java.lang.NullPointerException ex){}
     return null;
    }   
    
    private void generateSourceCodeSintaxImport(ArrayList<CodeContextLine> objSourceLinesCode){
        try{
            if(objComponente instanceof ComponenteGenerado){
                String strImport = "import " + objComponente.getObjClassSwing().getCanonicalName() + ";";
                CodeContextLine objSourceLineCode = new CodeContextLine(strImport);
                objSourceLinesCode.add(objSourceLineCode);
            }
            else if(objComponente instanceof ComponenteDistribuidorGeneradorUnitario){
                ComponenteDistribuidorGeneradorUnitario objComponenteDistribuidorGeneradorUnitario = (ComponenteDistribuidorGeneradorUnitario) objComponente;
                for(Componente objComponenteDistribuido : objComponenteDistribuidorGeneradorUnitario.getComponentesDistribuidos()){
                    if(objComponenteDistribuido instanceof ComponenteGenerado){
                        ComponenteGenerado objComponenteGenerado = (ComponenteGenerado) objComponenteDistribuido;
                        if(objComponenteGenerado.isIncluido()){
                            String strImport = "import " + objComponenteGenerado.getObjClassSwing().getCanonicalName() + ";";
                            CodeContextLine objSourceLineCode = new CodeContextLine(strImport);
                            objSourceLinesCode.add(objSourceLineCode);
                        }
                    }
                }
                String strImport = "import " + objComponenteDistribuidorGeneradorUnitario.getObjComponenteGenerador().getObjClassSwing().getCanonicalName() + ";";
                CodeContextLine objSourceLineCode = new CodeContextLine(strImport);
                objSourceLinesCode.add(objSourceLineCode);
            }
        }catch(java.lang.Exception ex){
            Logger.getLogger(CodeContextField.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }
    
    private void generateSourceCodeSintaxDefinition(ArrayList<CodeContextLine> objSourceLinesCode){
        try{
            if(objComponente instanceof ComponenteGenerado){                
                String strImport = "private " + 
                        ((definicionCanonica) ? objComponente.getObjClassSwing().getCanonicalName() : objComponente.getObjClassSwing().getSimpleName()) +
                        objComponente.getName() + ";";
                CodeContextLine objSourceLineCode = new CodeContextLine(strImport);
                objSourceLinesCode.add(objSourceLineCode);
            }                        
        }catch(java.lang.Exception ex){
            Logger.getLogger(CodeContextField.class.getName()).log(Level.SEVERE, null, ex);
        }        
    }

    @Override
    public CodeContextLine generateSingleSourceCodeSyntax(EnumTypeCodeSyntax eTypeCodeSintax) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public ArrayList<CodeContextLine> generateSourceCodeSyntaxString(String strEnumTypeCodeSintax) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public CodeContextLine generateSingleSourceCodeSyntax(String strEnumTypeCodeSintax) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
